{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "significant-stuart",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "guided-spelling",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 3,  3,  3,  3,  3],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. 算术运算\n",
    "a = np.arange(15).reshape((3,5))\n",
    "\n",
    "a2 = a + 3\n",
    "a3 = a - 5\n",
    "a5 = a * 2\n",
    "a6 = a / 3\n",
    "a7 = a ** 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "compound-scenario",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  1,  1,  1,  1],\n",
       "       [-1,  1, -1, -1,  1],\n",
       "       [ 1,  1, -1,  1, -1]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2. 逻辑运算\n",
    "a = np.random.randn(15).reshape((3,5))\n",
    "\n",
    "# 生成一个和a一样shape的数组，只包含True或False\n",
    "a > 0\n",
    "\n",
    "# 应用举例，根据Boole数组生成新的数组\n",
    "b = np.where(a>0, 1, -1)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "capital-shoot",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  5, 10, 15],\n",
       "        [20, 25, 30, 35],\n",
       "        [40, 45, 50, 55]],\n",
       "\n",
       "       [[ 1,  6, 11, 16],\n",
       "        [21, 26, 31, 36],\n",
       "        [41, 46, 51, 56]],\n",
       "\n",
       "       [[ 2,  7, 12, 17],\n",
       "        [22, 27, 32, 37],\n",
       "        [42, 47, 52, 57]],\n",
       "\n",
       "       [[ 3,  8, 13, 18],\n",
       "        [23, 28, 33, 38],\n",
       "        [43, 48, 53, 58]],\n",
       "\n",
       "       [[ 4,  9, 14, 19],\n",
       "        [24, 29, 34, 39],\n",
       "        [44, 49, 54, 59]]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3. 变换形状\n",
    "a = np.random.randn(15).reshape((3,5))\n",
    "a.reshape((5,3))\n",
    "a\n",
    "\n",
    "# 转置\n",
    "b = a.T\n",
    "b\n",
    "\n",
    "# 抽转换\n",
    "a = np.arange(60).reshape((3,4,5))\n",
    "b = a.transpose(2,0,1)\n",
    "b\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "shaped-clause",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-1.48908693  0.81147486  0.548572    0.19547187 -0.08622078 -0.05702969\n",
      " -1.44227199  1.44013649  0.82816367  0.17613013]\n",
      "[-1.48908693 -1.44227199 -0.08622078 -0.05702969  0.17613013  0.19547187\n",
      "  0.548572    0.81147486  0.82816367  1.44013649]\n",
      "[[[-0.08268428 -0.68317445  0.72382374  0.73592592  1.45240199]\n",
      "  [-0.50175579  0.24899196 -0.91435409 -1.31736004 -0.99254605]\n",
      "  [-0.57431822 -1.04006582  0.51281801  0.71044717  0.43136312]\n",
      "  [-1.17482668  0.42606772  0.01990746  0.6212776  -0.60506121]]\n",
      "\n",
      " [[ 1.05150362  2.17112286  0.01805424  1.9294565  -1.50818941]\n",
      "  [-1.86381752  1.01448176  0.24769879  0.03201179 -1.6628891 ]\n",
      "  [ 0.01166939  1.97224788  0.38519407  0.19778498 -1.04163552]\n",
      "  [ 0.30997722  0.09487772 -0.90125306 -0.10989398  0.10672492]]\n",
      "\n",
      " [[ 0.71503955 -0.35438363  0.13120773 -2.30314931 -0.72021267]\n",
      "  [-2.57437624 -0.20127417  0.86075823  1.09060925 -0.89720017]\n",
      "  [ 0.23461513  0.53845285 -0.68699132 -0.42351994  0.79212035]\n",
      "  [-1.0221935   1.04426719 -0.36229346 -0.94787395 -1.72750538]]]\n",
      "[[[-0.68317445 -0.08268428  0.72382374  0.73592592  1.45240199]\n",
      "  [-1.31736004 -0.99254605 -0.91435409 -0.50175579  0.24899196]\n",
      "  [-1.04006582 -0.57431822  0.43136312  0.51281801  0.71044717]\n",
      "  [-1.17482668 -0.60506121  0.01990746  0.42606772  0.6212776 ]]\n",
      "\n",
      " [[-1.50818941  0.01805424  1.05150362  1.9294565   2.17112286]\n",
      "  [-1.86381752 -1.6628891   0.03201179  0.24769879  1.01448176]\n",
      "  [-1.04163552  0.01166939  0.19778498  0.38519407  1.97224788]\n",
      "  [-0.90125306 -0.10989398  0.09487772  0.10672492  0.30997722]]\n",
      "\n",
      " [[-2.30314931 -0.72021267 -0.35438363  0.13120773  0.71503955]\n",
      "  [-2.57437624 -0.89720017 -0.20127417  0.86075823  1.09060925]\n",
      "  [-0.68699132 -0.42351994  0.23461513  0.53845285  0.79212035]\n",
      "  [-1.72750538 -1.0221935  -0.94787395 -0.36229346  1.04426719]]]\n"
     ]
    }
   ],
   "source": [
    "# 4. sort排序\n",
    "a = np.random.randn(10)\n",
    "print(a)\n",
    "a.sort()\n",
    "print(a)\n",
    "\n",
    "a = np.random.randn(60).reshape((3,4,5))\n",
    "print(a)\n",
    "a.sort(2)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "wireless-service",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
